<?php

namespace api\modules\v1\controllers;

use yii\web\Controller;
use Ramsey\Uuid\Uuid;

/**
 * Default controller for the `v1` module
 */
class DefaultController extends Controller
{
    public $enableCsrfValidation = false;
    /**
     * Renders the index view for the module
     * @return string
     */
    public function actionIndex()
    {
       return 'MiniProgram Test Return';
    }

    public  function  actionTest(){
        $uuid = str_replace('-', '', Uuid::uuid4()->toString());

         echo '<pre>';
         echo $uuid . "\n";
         echo strlen($uuid) . "\n";
         echo '------';
        $crc = sprintf('%x', sprintf('%u', crc32($uuid)));

         echo $crc . "\n";
         echo substr($uuid, 0, 2) . "\n" .
             substr($crc, 0, 2) . "\n" .
             substr($uuid, 2, strlen($uuid) - 2 - 3) . "\n" .
             substr($crc, strlen($crc) - 2, 2) . "\n" .
             substr($uuid, -3) .
             "";

        $newuuid = substr($uuid, 0, 2) .
            substr($crc, 0, 2) .
            substr($uuid, 2, strlen($uuid) - 2 - 3) .
            substr($crc, strlen($crc) - 2, 2) .
            substr($uuid, -3);

        var_dump($newuuid);
    }
}
